﻿using System;
using System.Drawing;
using System.Text;

namespace MathTools
{
    public class DoublePoint
    {
        public DoublePoint( double X, double Y )
        {
            this.X = X;
            this.Y = Y;
        }

        public DoublePoint()
            :this( 0, 0 )
        {
        }

        public DoublePoint( DoublePoint dp )
            : this( dp.X, dp.Y )
        {
        }
        public DoublePoint( Point p )
            : this( p.X, p.Y )
        {
        }
        public DoublePoint( Size s )
            : this( s.Width, s.Height )
        {
        }

        public bool isInfinity()
        {
            return Double.IsInfinity( X ) || Double.IsInfinity( Y );
        }

        public double absoluteValue()
        {
            return X * X + Y * Y;
        }

        #region Operators

        public static DoublePoint operator +( DoublePoint dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp2.X + dp1.X, dp2.Y + dp1.Y );
        }

        public static DoublePoint operator -( DoublePoint dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp1.X - dp2.X, dp1.Y - dp2.Y );
        }

        public static DoublePoint operator *( DoublePoint dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp2.X * dp1.X, dp2.Y * dp1.Y );
        }

        public static DoublePoint operator /( DoublePoint dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp1.X / dp2.X, dp1.Y / dp2.Y );
        }

        public static DoublePoint operator -( Double dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp1 - dp2.X, dp1 - dp2.Y );
        }

        public static DoublePoint operator /( DoublePoint dp1, Double dp2 )
        {
            return new DoublePoint( dp1.X / dp2, dp1.Y / dp2 );
        }

        public static DoublePoint operator *( DoublePoint dp1, Double dp2 )
        {
            return new DoublePoint( dp1.X * dp2, dp1.Y * dp2 );
        }

        public static DoublePoint operator *( Double dp1, DoublePoint dp2 )
        {
            return new DoublePoint( dp1 * dp2.X, dp1 * dp2.Y );
        }

        #endregion

        #region Public fields

        public double X { get; set; }
        public double Y { get; set; }

        public Point Point
        {
            get { return new Point( ( int )X, ( int )Y ); }
        }
                

        #endregion
    }

}
